﻿@{
    Layout = null;
}
@model System.Collections.IEnumerable
<!DOCTYPE html>

<html>
<head>
     @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>
    
    @Html.DevExpress().GetStyleSheets(
                new StyleSheet { ExtensionType = ExtensionType.GridView, Theme = DevExpressHelper.Theme }

    )
    @Html.DevExpress().GetScripts(
                    new Script { ExtensionType = ExtensionType.ListBox }
    )

    <script>
        $(function () {
            $("#toolMenu").smartFloat();

        });

        function OnBeginCallback(s, e) {
            e.customArgs["command"] = e.command;
            e.customArgs["pageIndex"] = s.pageIndex;
            e.customArgs["pageCount"] = s.pageCount;
            e.customArgs["pageRowSize"] = s.pageRowSize;
            e.customArgs["pageRowCount"] = s.pageRowCount;
            e.customArgs["paperTopicID"] = $('#hidpaperTopicID').val();

        }


        function MenuTop_emClick(source, e) {
            switch (e.item.name) {
                case "btnAdd":
                    {
                        //增加
                        PaperTopicAdd()
                        break;
                    }

                case "btnDelete":
                    {
                        //批量删除删除
                        PaperTopicManyDel();
                        break;
                    }
            }
        }

        function PaperTopicEdit(paperTopicId) {
            var rs = window.showModalDialog(rootPath+"/Admin/PaperTopic/PaperTopicContent?paperTopicId=" + paperTopicId, 'editPaperTopic', 'dialogWidth:800px;dialogHeight:700px');
            if (typeof (rs) != "undefined") {
                if (rs == "ok") {
                    window.location.href = window.location.href;
                }
            }
         }

         function PaperTopicAdd() {
             var rs = window.showModalDialog(rootPath + "/Admin/PaperTopic/PaperTopicContent?paperId=" + $("#hidpaperID").val(), 'addPaperTopic', 'dialogWidth:800px;dialogHeight:700px');
             if (typeof (rs) != "undefined") {
                 if (rs == "ok") {
                     window.location.href = window.location.href;
                 }
             }
          }


          function PaperTopicManyDel(topicIds) {
              var topicIds = gvEditing.GetSelectedKeysOnPage();
              if (topicIds.length == 0) {
                  alert("请选择要删除的数据");
              } else {
                  if (window.confirm("确定删除")) {
                      var topicIdArray = "";
                      for (var i = 0; i < topicIds.length; i++) {
                          topicIdArray += topicIds[i] + ",";
                      }

                      $.ajax({
                          type: 'POST',
                          url: rootPath + '/Admin/PaperTopic/DelTopicAndAnswerOptionMany',
                          data: { topicIds: topicIdArray },
                          success: function (result) {
                              if (result == "ok") {
                                  alert("删除成功!");
                                  location.reload();
                              } else if (result == "error") {
                                  alert("删除失败!");
                              } else if (result.indexOf("okExists_") != -1) {
                                  alert("批量删除成功，但有些题目已存在答题数据，无法删除");
                                  location.reload();                              
                              } else {
                                  alert("删除参数错误!");
                              }
                          }
                      });
                  }
             }
           }


           //删除
           function PaperTopicDel(paperTopicId) {
               if (window.confirm("确定删除")) {
                   $.ajax({
                       type: 'POST',
                       url: rootPath + '/Admin/PaperTopic/DelTopicAndAnswerOption',
                       data: { paperTopicId: paperTopicId },
                       success: function (result) {
                           if (result == "Exists") {
                               alert("该题目已有答题存在，无法删除");
                           } else if (result == "ok") {
                               alert("删除成功");
                               location.reload();
                           } else {
                               alert("删除失败");
                           }
                       }
                   });                    
                }
            }

    </script>


</head>


<body>
    <div>
        @Html.DevExpress().Menu(settings => 
        {
            settings.Name = "toolBarMenu";
            settings.ItemAutoWidth = false;
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
            settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
            settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

            settings.Items.Add(item =>
            {
                item.Name = "btnAdd";
                item.Text = "增加";
                item.Visible = (bool)ViewData["add"];
                item.Image.Url = Url.Content("~/Content/ControlImages/edit_add.png");

            });
            settings.Items.Add(item =>
            {
                item.Name = "btnDelete";
                item.Text = "删除";
                item.ItemStyle.ForeColor = System.Drawing.Color.Red;
                item.ClientEnabled = true;
                item.Image.Url = Url.Content("~/Content/ControlImages/cancel.png");

            });
            settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
            settings.ItemLinkMode = ItemLinkMode.ContentBounds;
        }).GetHtml()
    </div>
     @Html.Partial("PaperTopciListPartial", Model)
      @Html.Hidden("hidpaperTopicID", ViewData["paperTopicId"])
      @Html.Hidden("hidpaperID", ViewData["paperID"])
      @Html.Hidden("hidIsAnswer", ViewData["isAnswer"])
</body>
</html>
